package com.linewow.xhyy.nihaonew.view.input;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;

import com.linewow.xhyy.nihaonew.inter.RecorderInter;

/**
 * Created by LXR on 2016/9/2.
 */
public abstract class PrimaryMenuBase extends RelativeLayout implements RecorderInter {
    protected PrimaryListener listener;
    protected Activity activity;
    protected InputMethodManager inputMethodManager;
    public PrimaryMenuBase(Context context) {
        super(context);
        init(context);
    }

    public void setListener(PrimaryListener listener) {
        this.listener = listener;
    }

    private void init(Context context){
        this.activity= (Activity) context;
        this.inputMethodManager= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    }

    public PrimaryMenuBase(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public PrimaryMenuBase(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public interface PrimaryListener{
        void voiceClick();
        void imgClick();
        void sendMessage(String msg);
        void sendPathMessage(boolean flag);
        void sendPath(String path);
        void editChange();
    }

    public void hideKeyboard(){
        if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (activity.getCurrentFocus() != null)
                inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }


}
